#! /usr/bin/env python
# -*- coding: UTF-8 -*-
__author__ = 'xcma'
import sys

BASE_PATH = r"test_module/testcase/"

KUPU = 'kupu'

MODULE_LIST = [KUPU]
SMOKE = 'smoke'
DETAIL = 'detail'
SCENARIO = 'scenario'
RUN_DIR = {'all': BASE_PATH}

KUPU_SMOKE = f'{KUPU}_{SMOKE}'

KUPU_DETAIL = f'{KUPU}_{DETAIL}'

FDIR = [SMOKE, DETAIL, SCENARIO]


def runModule():
    for i in MODULE_LIST:
        RUN_DIR[f'{i}'] = f'{BASE_PATH}{i}'
        RUN_DIR[f'{i}_{SMOKE}'] = f'{BASE_PATH}{i}/{SMOKE}'
        RUN_DIR[f'{i}_{DETAIL}'] = f'{BASE_PATH}{i}/{DETAIL}'
        RUN_DIR[f'{i}_{SCENARIO}'] = f'{BASE_PATH}{i}/{SCENARIO}'
    return RUN_DIR


def switch_run_module(key):
    msg = '参数异常，请重新输入'
    try:
        RUN_DIR = runModule()
        chooseList = ','.join(RUN_DIR.keys())

        if '_' not in key:
            msg = f'------ERROR------ \n switch run module format error ;\n choose list :{chooseList} \n you input:【{key}】\n eg: admin_somke'
            raise msg
        else:
            kl = key.split('_')
            el = kl[-1]
            fl = '_'.join(kl[:-1])
            if fl not in MODULE_LIST or el not in FDIR:
                msg = f'------ERROR------ \n switch run module format error ; \n you input:【{key}】\n eg: admin_smoke'
                raise msg
        return RUN_DIR[key] if key in RUN_DIR else RUN_DIR['all']
    except:
        print(msg)
        sys.exit()
